package engine.gui.elements;

import org.lwjgl.opengl.GL11;

import engine.gui.Component;
import engine.gui.Font;
import engine.gui.GUIStyle;
import engine.util.ortho.Draw2D;
import engine.util.vector.Color;


public class Label extends Component{

	private String text;
	private boolean border;
	private boolean alignCenter;
	
	public Label() {
	}
	
	public Label(String text) {
		this();
		this.text = text;
	}
	
	public Label(String text, int posX, int posY, int width, int height) {
		this(text);
		setPosX(posX);
		setPosY(posY);
		setWidth(width);
		setHeight(height);
	}
	
	public Label(int posX, int posY, int width, int height) {
		this();
		setPosX(posX);
		setPosY(posY);
		setWidth(width);
		setHeight(height);
	}
	
	@Override
	public void render(int x, int y, int width, int height) {
		if(text != null) {
			GUIStyle style = getCurrentStyle();
			
			double h = style.getFont().getAscend();
			double w = style.getFont().getWidth(text);
			
			Color.bindColor4f(style.getLabelColor());
			if(alignCenter) {
				style.getFont().draw(text, x + getPosX() + (getWidth() - w) / 2, y + getPosY() + (h + getHeight()) / 2);
			} else {
				style.getFont().draw(text, x + getPosX() + 2, y + getPosY() + (h + getHeight()) / 2);
			}
		}
		
		if(isBorder()) {
			GL11.glColor4f(0, 0, 0, 1);
			Draw2D.drawRect(x + getPosX(), y + getPosY(), getWidth(), getHeight());
		}
	}
	
	@Override
	public void reset() {
		//do nothing
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public boolean isBorder() {
		return border;
	}

	public void setBorder(boolean border) {
		this.border = border;
	}

	public boolean isAlignCenter() {
		return alignCenter;
	}

	public void setAlignCenter(boolean center) {
		this.alignCenter = center;
	}
	
	public float[] getColor() {
		return getOwnStyle().getLabelColor();
	}
	
	public void setColor(float r, float g, float b, float a) {
		getOwnStyle().setLabelColor(r, g, b, a);
	}
	
	public void setFont(Font font) {
		getOwnStyle().setFont(font);
	}
	
	public Font getFont() {
		return getOwnStyle().getFont();
	}
}
